﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;

namespace Cotrobaie
{
    public class SendEmail
    {
        public static bool SendVerificationEmail(string Nume,string Prenume, string EmailAddress, string ActivationCode)
        {
            MailMessage ma = new MailMessage();
            string link = "http://cotrobaie.cjb.net//EmailVerif.aspx?ActivationCode=" + ActivationCode;
            ma.Body = "Salut " +Prenume+" "+ Nume + ",<br/><br/>Bine ai venit pe site-ul <a href='http://cotrobaie.cjb.net/' title='Cotrobaie.cbj.net'>Cotrobaie.cbj.net</a>. <br/>Pentru a finaliza inregistrarea te rugam acceseaza link-ul urmator: "
                + "<a href='" + link + "' title='click'>" + link + "</a><br/><br/>Daca nu tu esti cel care s-a inregistrat pe site-ul Cotrobaie.cbj.net, te rugam ignora acest mesaj<br/><br/><br/>"
                + "Multumim,<br/>Echipa Cotrobaie.cbj.net";
            ma.BodyEncoding = System.Text.Encoding.UTF8;
            ma.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
            ma.From = new MailAddress("ic.servicii@gmail.com", "Cotrobaie.cbj.net");
            ma.IsBodyHtml = true;
            ma.Priority = MailPriority.High;
            ma.Subject = "[Cotrobaie.cbj.net]Validare E-mail";
            ma.SubjectEncoding = System.Text.Encoding.UTF8;
            ma.To.Add(new MailAddress(EmailAddress));

            SmtpClient smtp = new SmtpClient("smtp.gmail.com ", 587);
            smtp.Credentials = new System.Net.NetworkCredential("ic.servicii@gmail.com", "salamdesobo");
            smtp.Timeout = 30000;//default e 100.000 adica 100 sec
            smtp.EnableSsl = true;
            try { smtp.Send(ma); }
            catch { return false; }
            ma.Dispose();
            smtp.Dispose();
            return true;
        }
        public static bool SendContactEmail(string Nume, string Prenume, string Email, string text)
        {
            MailMessage ma = new MailMessage();
            ma.Body = text + "<br/><br/>de la " + Nume + " " + Prenume + ", emal: " + Email;
            ma.BodyEncoding = System.Text.Encoding.UTF8;
            ma.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
            ma.From = new MailAddress(Email, Prenume+" "+Nume);
            ma.IsBodyHtml = true;
            ma.Priority = MailPriority.High;
            ma.Subject = "[Cotrobaie.cjb.net]Mesaj Contact";
            ma.SubjectEncoding = System.Text.Encoding.UTF8;
            ma.To.Add(new MailAddress("ic.servicii@gmail.com"));

            SmtpClient smtp = new SmtpClient("smtp.gmail.com ", 587);
            smtp.Credentials = new System.Net.NetworkCredential("ic.servicii@gmail.com", "salamdesobo");
            smtp.Timeout = 30000;//default e 100.000 adica 100 sec
            smtp.EnableSsl = true;
            try { smtp.Send(ma); }
            catch { return false; }
            ma.Dispose();
            smtp.Dispose();
            return true;
        }

        public static bool SendRecuperareParolaEmail(string Username, string Email, string ActivationCode)
        {
            MailMessage ma = new MailMessage();
            string link = "http://cotrobaie.cjb.net//RecuperareParola.aspx?ActivationCode=" + ActivationCode + "&user=" + Username+"&email="+Email;
            ma.Body = "Salut " + Username + ",<br/><br/>Acest E-mail a fost generat ca urmare a cererii dvs de recuperare a parolei.<br/>Pentru a continua procesul de generare a unei noi parole te rugam acceseaza link-ul urmator: "
                + "<a href='" + link + "' title='click'>" + link + "</a><br/><br/>Daca nu tu esti cel care a dorit recuperarea parolei, te rugam ignora acest mesaj<br/><br/><br/>"
                + "Multumim,<br/>Echipa Cotrobaie.cbj.net";
            ma.BodyEncoding = System.Text.Encoding.UTF8;
            ma.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
            ma.From = new MailAddress("ic.servicii@gmail.com", "Cotrobaie.cbj.net");
            ma.IsBodyHtml = true;
            ma.Priority = MailPriority.High;
            ma.Subject = "[Cotrobaie.cbj.net]RecupereazaParola";
            ma.SubjectEncoding = System.Text.Encoding.UTF8;
            ma.To.Add(new MailAddress(Email));

            SmtpClient smtp = new SmtpClient("smtp.gmail.com ", 587);
            smtp.Credentials = new System.Net.NetworkCredential("ic.servicii@gmail.com", "salamdesobo");
            smtp.Timeout = 30000;//default e 100.000 adica 100 sec
            smtp.EnableSsl = true;
            try { smtp.Send(ma); }
            catch { return false; }
            ma.Dispose();
            smtp.Dispose();
            return true;
        }
    }
}